package com.javaee.controller.admin;

import com.javaee.BeforeBaseController;
import com.javaee.entity.Doctor;

import com.javaee.service.admin.DoctorService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;

@Controller
@RequestMapping("/doctor")
public class DoctorController  extends BeforeBaseController{
    @Autowired
    private DoctorService doctorService;

    @RequestMapping("/toAddDoctor")
    public String toAddDoctor(Doctor doctor, Model model) {

        return doctorService.toAddDoctor(doctor, model);
    }

    @RequestMapping("/addDoctor")
    public String addDoctor(@ModelAttribute("doctor") Doctor doctor, HttpServletRequest request) throws IllegalStateException, IOException {

        return doctorService.addDoctor(doctor, request);
    }

    @RequestMapping("/selectAllDoctorsByPage")
    public String selectAllDoctorsByPage(Model model, int currentPage) {
        return doctorService.selectAllDoctorsByPage(model, currentPage);
    }

    @RequestMapping("/detail")
    public String detail(Model model, Integer id) {
        return doctorService.detail(model, id);
    }

    @RequestMapping("/delete")
    @ResponseBody
    public String delete(Integer id) {
        return doctorService.delete(id);
    }

    @RequestMapping("/toUpdate")
    public String toUpdate(Model model, Integer id) {
        return doctorService.toUpdate(model, id);
    }

    @RequestMapping("/update")
    public String update(Doctor doctor, @RequestParam(name = "people",required = false) String people, HttpServletRequest request) throws Exception {
        System.out.println(doctor + "jjjjjjjj");
        return doctorService.update(doctor, people,request);
    }
}